Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change celery pool support from prefork to threads #1437

Merged
merged 7 commits into from
Jan 7, 2025
Merged

Conversation

terrazoon
Copy link
Contributor

@terrazoon terrazoon commented Nov 25, 2024

Description

The article referenced in issue #1432 says that prefork is the default pool support for Celery because it is robust and pythonic and good for CPU bound apps. The problem becomes when you have an IO bound app, and you find out that prefork is a CPU hog. Prefork holds onto CPU utilization even when nothing is going on. Our last load test showed that we seemed to exceed our allocated CPU utilization by a wide margin and this seemed to destabilize the app towards the end of the test.

By switching to threads, we will have more concurrency, less CPU utilization, and less memory utilization. ASSUMING IT IS STABLE. The caveats are that everything has to be thread safe. We are currently using multiprocessing.Manager (thread safe) and ThreadPoolExecutor (thread safe) so we might be good here.

Testing locally this of course works perfectly fine. We should do a load test on production after hours and see if this would be a viable approach.

Security Considerations

@terrazoon terrazoon changed the title change celery pool support from prefork to threads EXPERIMENTAL: change celery pool support from prefork to threads Nov 25, 2024
@terrazoon terrazoon self-assigned this Nov 25, 2024
@terrazoon terrazoon changed the title EXPERIMENTAL: change celery pool support from prefork to threads change celery pool support from prefork to threads Jan 2, 2025
Copy link
Contributor

@xlorepdarkhelm xlorepdarkhelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, the old "multiprocessing vs threading" problem.

Which is truly solved with "async", but that's a heavy rewrite for a different decade.

this will, I believe, make the celery stuff become single-core. unless it has independent banaries outside of Python that are handling it, then it might just in general be better.

Copy link
Contributor

@ccostino ccostino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @terrazoon! Let's see if this works as we expect it to!

@ccostino ccostino merged commit 9e4e957 into main Jan 7, 2025
7 checks passed
@ccostino ccostino deleted the notify-api-1432 branch January 7, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Research adjusting the prefork setting for Celery and write an ADR proposing adjustments
3 participants